package GUI_boekwerk;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.Timer;

@SuppressWarnings("serial")
public class TimerPanel extends JPanel
{
	private int teller;
	private Timer timer;
	private JButton start, stop;
	
	public TimerPanel()
	{
		teller = 0;
		timer = new Timer(100, new TimerHandler());
		
		start = new JButton("Start");
		stop = new JButton("Stop");
		
		add(start);
		add(stop);
		
		KnopHandler kh = new KnopHandler();
		start.addActionListener(kh);
		stop.addActionListener(kh);
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(Color.BLUE);
		g.setFont(new Font("VERDANA", Font.BOLD, 14));
		g.drawString("Teller: "+teller, 130, 80);
	}
	
	class TimerHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			teller++;
			repaint();
		}
	}
	class KnopHandler implements ActionListener
	{
		public void actionPerformed(ActionEvent e) 
		{
			if(e.getSource() == start)
			{
				timer.start();
			}
			if(e.getSource() == stop)
			{
				timer.stop();
			}
		}
	}
}
